home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C & C++ Multimedia Cyber Classroom
/
C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso
/
cpphtp2
/
code.jar
/
code
/
ch03
/
fig03_08.txt
< prev
next >
Wrap
Text File
|
1998-02-27
|
1KB
|
51 lines
1 // Fig. 3.8: fig03_08.cpp
2 // Roll a six-sided die 6000 times
3 #include <iostream.h>
4 #include <iomanip.h>
5 #include <stdlib.h>
6
7 int main()
8 {
9 int frequency1 = 0, frequency2 = 0,
10 frequency3 = 0, frequency4 = 0,
11 frequency5 = 0, frequency6 = 0,
12 face;
13
14 for ( int roll = 1; roll <= 6000; roll++ ) {
15 face = 1 + rand() % 6;
16
17 switch ( face ) {
18 case 1:
19 ++frequency1;
20 break;
21 case 2:
22 ++frequency2;
23 break;
24 case 3:
25 ++frequency3;
26 break;
27 case 4:
28 ++frequency4;
29 break;
30 case 5:
31 ++frequency5;
32 break;
33 case 6:
34 ++frequency6;
35 break;
36 default:
37 cout << "should never get here!";
38 }
39 }
40
41 cout << "Face" << setw( 13 ) << "Frequency"
42 << "\n 1" << setw( 13 ) << frequency1
43 << "\n 2" << setw( 13 ) << frequency2
44 << "\n 3" << setw( 13 ) << frequency3
45 << "\n 4" << setw( 13 ) << frequency4
46 << "\n 5" << setw( 13 ) << frequency5
47 << "\n 6" << setw( 13 ) << frequency6 << endl;
48
49 return 0;
50 }